/**
 * @preserve Galleria Classic Theme 2011-06-07
 * http://galleria.aino.se
 *
 * Copyright (c) 2011, Aino
 * Licensed under the MIT license.
 */
 
/*global jQuery, Galleria */

(function($) {
	Galleria.addTheme({
	    name: 'classic',
	    author: 'Galleria',
	    css: '../css/galleria.classic.css',
	    defaults: {
	        transition: 'slide',
	        thumbCrop:  'height'
	    },
	    init: function(options) {
	        
	        // cache some stuff
	        var touch = Galleria.TOUCH,
	            click = touch ? 'touchstart' : 'click';
	        
	        // show loader & counter with opacity
	        this.$('loader,counter').show().css('opacity', 0.4);
	
	        // some stuff for non-touch browsers
	        if (! touch ) {
	            this.addIdleState( this.get('image-nav-left'), { left:-50 });
	            this.addIdleState( this.get('image-nav-right'), { right:-50 });
	            this.addIdleState( this.get('counter'), { opacity:0 });
	        }
	        
	        // bind some stuff
	        this.bind('thumbnail', function(e) {
	            
	            if (! touch ) {
	                // fade thumbnails
	                $(e.thumbTarget).css('opacity', 0.6).parent().hover(function() {
	                    $(this).not('.active').children().stop().fadeTo(100, 1);
	                }, function() {
	                    $(this).not('.active').children().stop().fadeTo(400, 0.6);
	                });
	                
	                if ( e.index === options.show ) {
	                    $(e.thumbTarget).css('opacity',1);
	                }
	            } else {
	                $(e.thumbTarget).css('opacity', e.index == options.show ? 1 : 0.6);
	            }
	        });
	        
	        this.bind('loadstart', function(e) {
	            if (!e.cached) {
	                this.$('loader').show().fadeTo(200, 0.4);
	            }
	            
	            $(e.thumbTarget).css('opacity',1).parent().siblings().children().css('opacity', 0.6);
	        });
	        
	        this.bind('loadfinish', function(e) {
	            this.$('loader').fadeOut(200);
	        });
	    }
	});
}(jQuery));

$(document).ready(function(){
	Galleria.loadTheme('../js/galleria.classic.js');
	$('#galleria').galleria();
});